@nanocollective/roster 0.1.0-beta.3 → 0.1.0-beta.30

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (135) hide show
  1. package/README.md +8 -0
  2. package/dist/agents-POITEZRI.js +232 -0
  3. package/dist/chunk-FF2WBNNW.js +370 -0
  4. package/dist/chunk-GDAJPOHK.js +562 -0
  5. package/dist/cli.js +3391 -1239
  6. package/dist/compose-5DBEHSEV.js +17 -0
  7. package/dist/connectors-5E5ZMGZV.js +23 -0
  8. package/dist/worker/assets/assets/css/astryx.css +948 -0
  9. package/dist/worker/assets/assets/css/base.css +51 -110
  10. package/dist/worker/assets/assets/css/brain.css +26 -2
  11. package/dist/worker/assets/assets/css/connectors.css +58 -0
  12. package/dist/worker/assets/assets/css/graph.css +9 -12
  13. package/dist/worker/assets/assets/css/health.css +4 -7
  14. package/dist/worker/assets/assets/css/home.css +145 -60
  15. package/dist/worker/assets/assets/css/inbox.css +11 -0
  16. package/dist/worker/assets/assets/css/layout.css +18 -22
  17. package/dist/worker/assets/assets/css/markdown.css +22 -1
  18. package/dist/worker/assets/assets/css/routines.css +40 -0
  19. package/dist/worker/assets/assets/css/runs.css +5 -3
  20. package/dist/worker/assets/assets/css/search.css +3 -6
  21. package/dist/worker/assets/assets/css/setup.css +3 -15
  22. package/dist/worker/assets/assets/js/api.js +3 -0
  23. package/dist/worker/assets/assets/js/app.js +25 -1
  24. package/dist/worker/assets/assets/js/astryx-ui.js +34 -0
  25. package/dist/worker/assets/assets/js/dom.js +1 -1
  26. package/dist/worker/assets/assets/js/homesort.js +66 -20
  27. package/dist/worker/assets/assets/js/icons.js +6 -0
  28. package/dist/worker/assets/assets/js/md.js +7 -2
  29. package/dist/worker/assets/assets/js/refcard.js +216 -0
  30. package/dist/worker/assets/assets/js/refresh.js +4 -2
  31. package/dist/worker/assets/assets/js/report.js +51 -0
  32. package/dist/worker/assets/assets/js/select.js +362 -0
  33. package/dist/worker/assets/assets/js/state.js +14 -1
  34. package/dist/worker/assets/assets/js/views/connectors.js +423 -0
  35. package/dist/worker/assets/assets/js/views/graph.js +67 -28
  36. package/dist/worker/assets/assets/js/views/home.js +378 -176
  37. package/dist/worker/assets/assets/js/views/inbox.js +68 -16
  38. package/dist/worker/assets/assets/js/views/org.js +2 -0
  39. package/dist/worker/assets/assets/js/views/people.js +109 -0
  40. package/dist/worker/assets/assets/js/views/routines.js +378 -0
  41. package/dist/worker/assets/assets/js/views/runs.js +3 -1
  42. package/dist/worker/assets/docs-images/brain.jpg +0 -0
  43. package/dist/worker/assets/docs-images/home.jpg +0 -0
  44. package/dist/worker/assets/docs-images/org.jpg +0 -0
  45. package/dist/worker/assets/docs-images/prompt.jpg +0 -0
  46. package/dist/worker/assets/docs-images/setup-org.jpg +0 -0
  47. package/dist/worker/assets/docs-images/setup-plan.jpg +0 -0
  48. package/dist/worker/assets/docs-images/staff.jpg +0 -0
  49. package/dist/worker/assets/index.html +19 -3
  50. package/dist/worker/index.js +4478 -1098
  51. package/docs/README.md +2 -0
  52. package/docs/architecture.md +23 -4
  53. package/docs/commands.md +111 -9
  54. package/docs/concepts.md +2 -1
  55. package/docs/connectors.md +169 -0
  56. package/docs/cost.md +1 -1
  57. package/docs/developing.md +3 -3
  58. package/docs/doctor-codes.md +8 -2
  59. package/docs/export.md +4 -3
  60. package/docs/extending.md +1 -1
  61. package/docs/getting-started.md +20 -3
  62. package/docs/hosting.md +67 -3
  63. package/docs/images/brain.jpg +0 -0
  64. package/docs/images/home.jpg +0 -0
  65. package/docs/images/org.jpg +0 -0
  66. package/docs/images/prompt.jpg +0 -0
  67. package/docs/images/setup-org.jpg +0 -0
  68. package/docs/images/setup-plan.jpg +0 -0
  69. package/docs/images/staff.jpg +0 -0
  70. package/docs/memory.md +3 -2
  71. package/docs/org-yaml.md +58 -5
  72. package/docs/portal.md +52 -11
  73. package/docs/prompts.md +3 -2
  74. package/docs/routines.md +65 -0
  75. package/docs/security.md +37 -4
  76. package/docs/session-workflow.md +31 -8
  77. package/docs/staff-yaml.md +7 -3
  78. package/docs/troubleshooting.md +1 -1
  79. package/docs/upgrading.md +1 -1
  80. package/docs/writing-a-charter.md +1 -1
  81. package/package.json +8 -1
  82. package/templates/brain/.gitattributes +3 -0
  83. package/templates/brain/.github/workflows/%%STAFF%%-daily.yaml +24 -15
  84. package/templates/brain/.github/workflows/%%STAFF%%-mention.yaml +12 -10
  85. package/templates/brain/CHARTER.md +2 -2
  86. package/templates/brain/STATE.md +16 -0
  87. package/templates/brain/memory/INDEX.md +1 -1
  88. package/templates/brain/staff.yaml +3 -0
  89. package/templates/ops/.gitattributes +3 -0
  90. package/templates/ops/.github/workflows/session.yaml +92 -13
  91. package/templates/ops/agents.mjs +38 -11
  92. package/templates/ops/compose.mjs +60 -2
  93. package/templates/ops/connectors.mjs +722 -0
  94. package/templates/ops/org/operating.md +10 -0
  95. package/templates/ops/org/voice.md +21 -3
  96. package/templates/ops/prompts/_identity.md +20 -0
  97. package/templates/ops/prompts/daily.md +70 -19
  98. package/templates/ops/prompts/mention.md +7 -2
  99. package/templates/ops/status-week.mjs +169 -0
  100. package/templates/portal/css/astryx.css +948 -0
  101. package/templates/portal/css/base.css +51 -110
  102. package/templates/portal/css/brain.css +26 -2
  103. package/templates/portal/css/connectors.css +58 -0
  104. package/templates/portal/css/graph.css +9 -12
  105. package/templates/portal/css/health.css +4 -7
  106. package/templates/portal/css/home.css +145 -60
  107. package/templates/portal/css/inbox.css +11 -0
  108. package/templates/portal/css/layout.css +18 -22
  109. package/templates/portal/css/markdown.css +22 -1
  110. package/templates/portal/css/routines.css +40 -0
  111. package/templates/portal/css/runs.css +5 -3
  112. package/templates/portal/css/search.css +3 -6
  113. package/templates/portal/css/setup.css +3 -15
  114. package/templates/portal/index.html +19 -3
  115. package/templates/portal/js/api.js +3 -0
  116. package/templates/portal/js/app.js +25 -1
  117. package/templates/portal/js/astryx-ui.js +34 -0
  118. package/templates/portal/js/dom.js +1 -1
  119. package/templates/portal/js/homesort.js +66 -20
  120. package/templates/portal/js/icons.js +6 -0
  121. package/templates/portal/js/md.js +7 -2
  122. package/templates/portal/js/refcard.js +216 -0
  123. package/templates/portal/js/refresh.js +4 -2
  124. package/templates/portal/js/report.js +51 -0
  125. package/templates/portal/js/select.js +362 -0
  126. package/templates/portal/js/state.js +14 -1
  127. package/templates/portal/js/views/connectors.js +423 -0
  128. package/templates/portal/js/views/graph.js +67 -28
  129. package/templates/portal/js/views/home.js +378 -176
  130. package/templates/portal/js/views/inbox.js +68 -16
  131. package/templates/portal/js/views/org.js +2 -0
  132. package/templates/portal/js/views/people.js +109 -0
  133. package/templates/portal/js/views/routines.js +378 -0
  134. package/templates/portal/js/views/runs.js +3 -1
  135. package/templates/skill/SKILL.md +115 -0
package/README.md CHANGED
@@ -15,6 +15,14 @@ It runs every day against a live org: a CTO and a CMO have built and marketed
15
15
 
16
16
  ## Quick start
17
17
 
18
+ Paste this into a coding agent on your computer (Claude Code, Codex, Cursor, Gemini CLI):
19
+
20
+ ```
21
+ set up https://roster.nanocollective.org/SKILL.md
22
+ ```
23
+
24
+ Or run it yourself:
25
+
18
26
  ```bash
19
27
  npx @nanocollective/roster
20
28
  ```
@@ -0,0 +1,232 @@
1
+ #!/usr/bin/env node
2
+ import {
3
+ parseYaml
4
+ } from "./chunk-FF2WBNNW.js";
5
+
6
+ // templates/ops/agents.mjs
7
+ import { readFileSync } from "fs";
8
+ import { join } from "path";
9
+ var CLAUDE_TOOLS = {
10
+ full: '--allowedTools "Bash,Read,Write,Edit,Glob,Grep,WebFetch,WebSearch"',
11
+ workspace: '--allowedTools "Bash,Read,Write,Edit,Glob,Grep"',
12
+ "read-only": '--allowedTools "Read,Glob,Grep,WebFetch,WebSearch"'
13
+ };
14
+ function shellArg(v) {
15
+ return `'${String(v).replace(/'/g, "'\\''")}'`;
16
+ }
17
+ var PRESETS = {
18
+ // The reference runner, and the default. Uses Anthropic's own action, which handles tool
19
+ // permissions and output for us.
20
+ "claude-code-action": {
21
+ kind: "action",
22
+ token_env: "CLAUDE_CODE_OAUTH_TOKEN",
23
+ model: "claude-opus-5-5",
24
+ permissions: CLAUDE_TOOLS,
25
+ option: (k, v) => `--${k} ${shellArg(v)}`
26
+ },
27
+ // The same agent through its plain CLI, for anyone who would rather not depend on the action.
28
+ claude: {
29
+ kind: "cli",
30
+ install: "npm install -g @anthropic-ai/claude-code",
31
+ // JSON rather than text so the run record can read turns and cost off it. The log still
32
+ // carries the answer, inside the `result` field.
33
+ run: 'claude -p --model "$AGENT_MODEL" $AGENT_FLAGS --output-format json < "$AGENT_PROMPT_FILE" | tee "$AGENT_RESULT_FILE"',
34
+ token_env: "CLAUDE_CODE_OAUTH_TOKEN",
35
+ model: "claude-opus-5-5",
36
+ permissions: CLAUDE_TOOLS,
37
+ option: (k, v) => `--${k} ${shellArg(v)}`
38
+ },
39
+ codex: {
40
+ kind: "cli",
41
+ install: "npm install -g @openai/codex",
42
+ // `exec -` reads the prompt from stdin. The sandbox has to be opened up because the whole
43
+ // point of a session is that it edits the checkout and pushes.
44
+ run: 'codex exec - --model "$AGENT_MODEL" $AGENT_FLAGS < "$AGENT_PROMPT_FILE"',
45
+ token_env: "CODEX_API_KEY",
46
+ model: "gpt-5-codex",
47
+ /* Codex spells freedom as a sandbox plus an approval policy, and both have to be said:
48
+ a sandbox that allows writes still stops to ask by default, and a run that stops to ask
49
+ at 07:00 is a run that times out having done nothing. */
50
+ permissions: {
51
+ full: '--sandbox danger-full-access -c approval_policy="never"',
52
+ workspace: '--sandbox workspace-write -c approval_policy="never"',
53
+ "read-only": '--sandbox read-only -c approval_policy="never"'
54
+ },
55
+ // `-c key=value` is its highest-precedence override, so anything else goes through it.
56
+ option: (k, v) => `-c ${k}=${shellArg(JSON.stringify(v))}`
57
+ },
58
+ nanocoder: {
59
+ kind: "cli",
60
+ install: "npm install -g @nanocollective/nanocoder",
61
+ /* `run` is its non-interactive mode; --trust-directory skips the first-run prompt that
62
+ would otherwise hang a runner, and --plain avoids the TUI. The prompt is an argument
63
+ here rather than stdin, so it is read out of the file.
64
+
65
+ NANOCODER_PROVIDERS_FILE is the part that makes it work unattended. Nanocoder is a
66
+ client, not a model: it reads its providers from `agents.config.json` found in the
67
+ working directory. In a session that directory is the workspace root — the place the
68
+ repos are checked out *into* — which belongs to no repo, so a committed config would
69
+ never be found. Pointing at the ops repo's copy gives every staff member the same
70
+ providers from a file that is version controlled. A missing file is ignored, so this is
71
+ safe when somebody has configured it another way. */
72
+ run: 'NANOCODER_PROVIDERS_FILE="${NANOCODER_PROVIDERS_FILE:-roster-ops/agents.config.json}" nanocoder --model "$AGENT_MODEL" $AGENT_FLAGS --trust-directory --plain run "$(cat "$AGENT_PROMPT_FILE")"',
73
+ token_env: "NANOCODER_API_KEY",
74
+ model: "",
75
+ /* Its development modes. `plan` is genuinely read-only: it reasons and proposes and edits
76
+ nothing, which is the right answer for a staff member you are not ready to trust yet. */
77
+ permissions: {
78
+ full: "--mode yolo",
79
+ workspace: "--mode auto-accept",
80
+ "read-only": "--mode plan"
81
+ },
82
+ option: (k, v) => `--${k} ${shellArg(v)}`,
83
+ /* A client rather than a model, so it cannot run until it has been told whose model to
84
+ call. Written on init and reported by doctor when it is missing, because the failure
85
+ without it is a run that installs, starts, finds no provider and exits. */
86
+ config: {
87
+ path: "agents.config.json",
88
+ contents: {
89
+ nanocoder: {
90
+ providers: [
91
+ {
92
+ name: "openrouter",
93
+ baseUrl: "https://openrouter.ai/api/v1",
94
+ apiKey: "${NANOCODER_API_KEY}",
95
+ models: ["FILL IN: a model this provider serves, and set it as `model` in org.yaml"]
96
+ }
97
+ ]
98
+ }
99
+ }
100
+ }
101
+ }
102
+ };
103
+ function resolveAgent(org, staff = {}, extra = {}) {
104
+ const asked = staff.agent ?? org.agent ?? {};
105
+ const spec = typeof asked === "string" ? { id: asked } : asked;
106
+ const id = spec.id ?? "claude-code-action";
107
+ const preset = PRESETS[id];
108
+ if (!preset && !(spec.install && spec.run)) {
109
+ throw new Error(
110
+ `unknown agent "${id}", and no install/run given.
111
+ Known: ${Object.keys(PRESETS).join(", ")}
112
+ Or describe your own in org.yaml:
113
+ agent:
114
+ id: ${id}
115
+ install: <shell>
116
+ run: <shell>
117
+ token_env: <VAR>`
118
+ );
119
+ }
120
+ const merged = { kind: "cli", ...preset ?? {}, ...strip(spec) };
121
+ if (merged.kind === "cli" && !merged.run) throw new Error(`agent "${id}" has no run command`);
122
+ if (!merged.token_env) throw new Error(`agent "${id}" does not say which env var carries its credential`);
123
+ return {
124
+ id,
125
+ kind: merged.kind,
126
+ install: merged.install ?? "",
127
+ run: merged.run ?? "",
128
+ token_env: merged.token_env,
129
+ // The staff member's own model wins; then the agent's default. Empty means "the agent's".
130
+ model: staff.model ?? merged.model ?? "",
131
+ flags: flagsFor(merged, spec, org, staff, extra),
132
+ config: merged.config ?? null
133
+ };
134
+ }
135
+ var LEVELS = ["read-only", "workspace", "full"];
136
+ function flagsFor(merged, spec, org, staff, extra = {}) {
137
+ const out = [];
138
+ const asked = permissionOf(org, staff);
139
+ const tools = staff.allowed_tools ?? org.defaults?.allowed_tools;
140
+ const table = merged.permissions;
141
+ const more = (extra.tools ?? []).filter(Boolean);
142
+ if (table === CLAUDE_TOOLS) {
143
+ const base = tools ? (Array.isArray(tools) ? tools.join(",") : String(tools)).replace(/\s+/g, "") : CLAUDE_TOOLS[asked].match(/"([^"]*)"/)[1];
144
+ out.push(`--allowedTools "${[base, ...more].filter(Boolean).join(",")}"`);
145
+ } else if (table) {
146
+ out.push(table[asked]);
147
+ }
148
+ if (extra.flags) out.push(extra.flags);
149
+ const options = { ...spec.options ?? {}, ...staff.options ?? {} };
150
+ const speller = merged.option;
151
+ for (const [k, v] of Object.entries(options)) {
152
+ if (v === void 0 || v === null || v === "") continue;
153
+ if (!speller) {
154
+ throw new Error(
155
+ `agent "${merged.id ?? "custom"}" has options but no way to spell them.
156
+ A custom agent takes its options in its own \`run\` command.`
157
+ );
158
+ }
159
+ out.push(speller(k, v));
160
+ }
161
+ return out.filter(Boolean).join(" ");
162
+ }
163
+ function permissionOf(org, staff = {}) {
164
+ const agent = staff.agent ?? org.agent;
165
+ const spec = agent && typeof agent === "object" ? agent : {};
166
+ const level = staff.permissions ?? spec.permissions ?? org.permissions ?? "full";
167
+ if (!LEVELS.includes(level)) {
168
+ throw new Error(`unknown permissions "${level}". One of: ${LEVELS.join(", ")}`);
169
+ }
170
+ return level;
171
+ }
172
+ function strip(o) {
173
+ const out = {};
174
+ for (const [k, v] of Object.entries(o)) if (v !== void 0 && v !== null && v !== "") out[k] = v;
175
+ delete out.id;
176
+ delete out.permissions;
177
+ return out;
178
+ }
179
+ if (import.meta.url === `file://${process.argv[1]}`) {
180
+ const args = process.argv.slice(2);
181
+ const at = (flag) => {
182
+ const i = args.indexOf(flag);
183
+ return i === -1 ? void 0 : args[i + 1];
184
+ };
185
+ const opsDir = at("--ops") ?? "roster-ops";
186
+ const brainsDir = at("--brains") ?? ".";
187
+ const handle = at("--staff");
188
+ const org = parseYaml(readFileSync(join(opsDir, "org.yaml"), "utf8"), "org.yaml");
189
+ const entry = (org.staff ?? []).find((s) => s.handle === handle);
190
+ if (!entry) {
191
+ process.stderr.write(`agents: no staff member "${handle}" in org.yaml
192
+ `);
193
+ process.exit(2);
194
+ }
195
+ let manifest = {};
196
+ try {
197
+ const dir = entry.dir ?? entry.handle;
198
+ manifest = parseYaml(readFileSync(join(brainsDir, dir, "staff.yaml"), "utf8"), "staff.yaml");
199
+ } catch {
200
+ }
201
+ let wiring = {};
202
+ if (process.env.ROSTER_CONNECTORS) {
203
+ try {
204
+ wiring = JSON.parse(readFileSync(process.env.ROSTER_CONNECTORS, "utf8"));
205
+ } catch {
206
+ process.stderr.write("agents: the connectors' wiring could not be read, so none are used\n");
207
+ }
208
+ }
209
+ const agent = resolveAgent(org, manifest, wiring);
210
+ const out = [
211
+ `kind=${agent.kind}`,
212
+ `id=${agent.id}`,
213
+ `token_env=${agent.token_env}`,
214
+ `model=${agent.model}`,
215
+ `install<<AGENT_EOF_9c1f
216
+ ${agent.install}
217
+ AGENT_EOF_9c1f`,
218
+ `run<<AGENT_EOF_9c1f
219
+ ${agent.run}
220
+ AGENT_EOF_9c1f`,
221
+ `flags<<AGENT_EOF_9c1f
222
+ ${agent.flags}
223
+ AGENT_EOF_9c1f`
224
+ ].join("\n");
225
+ process.stdout.write(out + "\n");
226
+ }
227
+ export {
228
+ LEVELS,
229
+ PRESETS,
230
+ permissionOf,
231
+ resolveAgent
232
+ };
@@ -0,0 +1,370 @@
1
+ // templates/ops/compose.mjs
2
+ import * as nodeFs from "fs";
3
+ import { join, dirname, resolve } from "path";
4
+ import { fileURLToPath } from "url";
5
+ var { connectorsOf } = await import("./connectors-5E5ZMGZV.js").catch(() => ({ connectorsOf: () => [] }));
6
+ function parseYaml(text, file = "<yaml>") {
7
+ const lines = [];
8
+ text.split("\n").forEach((raw, i) => {
9
+ const noComment = stripComment(raw);
10
+ if (!noComment.trim()) return;
11
+ if (noComment.trim() === "---") return;
12
+ lines.push({ n: i + 1, indent: raw.match(/^ */)[0].length, text: noComment.trimEnd() });
13
+ });
14
+ let pos = 0;
15
+ const fail = (msg, line) => {
16
+ throw new Error(`${file}:${line?.n ?? "?"} ${msg}`);
17
+ };
18
+ function parseBlock(indent) {
19
+ const first = lines[pos];
20
+ if (!first) return null;
21
+ if (first.text.trim().startsWith("- ")) return parseList(indent);
22
+ return parseMap(indent);
23
+ }
24
+ function parseMap(indent) {
25
+ const out = {};
26
+ while (pos < lines.length) {
27
+ const line = lines[pos];
28
+ if (line.indent < indent) break;
29
+ if (line.indent > indent) fail("unexpected indentation", line);
30
+ const body = line.text.trim();
31
+ if (body.startsWith("- ")) break;
32
+ const m = body.match(/^([A-Za-z0-9_.-]+):\s*(.*)$/);
33
+ if (!m) fail(`expected "key: value", got ${JSON.stringify(body)}`, line);
34
+ const [, key, rest] = m;
35
+ pos++;
36
+ if (rest === "") {
37
+ const next = lines[pos];
38
+ if (next && next.indent > indent) out[key] = parseBlock(next.indent);
39
+ else out[key] = null;
40
+ } else {
41
+ out[key] = parseScalar(rest, line);
42
+ }
43
+ }
44
+ return out;
45
+ }
46
+ function parseList(indent) {
47
+ const out = [];
48
+ while (pos < lines.length) {
49
+ const line = lines[pos];
50
+ if (line.indent < indent) break;
51
+ const body = line.text.trim();
52
+ if (!body.startsWith("- ")) break;
53
+ if (line.indent > indent) fail("unexpected indentation in list", line);
54
+ const item = body.slice(2).trim();
55
+ pos++;
56
+ if (item.startsWith("{") && item.endsWith("}")) {
57
+ out.push(parseInlineMap(item, line));
58
+ } else if (/^[A-Za-z0-9_.-]+:/.test(item)) {
59
+ const sub = { ...parseInlinePair(item, line) };
60
+ while (pos < lines.length && lines[pos].indent > indent) {
61
+ const c = lines[pos];
62
+ const cm = c.text.trim().match(/^([A-Za-z0-9_.-]+):\s*(.*)$/);
63
+ if (!cm) fail(`expected "key: value" in list item, got ${JSON.stringify(c.text.trim())}`, c);
64
+ pos++;
65
+ if (cm[2] === "") {
66
+ const next = lines[pos];
67
+ sub[cm[1]] = next && next.indent > c.indent ? parseBlock(next.indent) : null;
68
+ } else {
69
+ sub[cm[1]] = parseScalar(cm[2], c);
70
+ }
71
+ }
72
+ out.push(sub);
73
+ } else {
74
+ out.push(parseScalar(item, line));
75
+ }
76
+ }
77
+ return out;
78
+ }
79
+ function parseInlinePair(item, line) {
80
+ const m = item.match(/^([A-Za-z0-9_.-]+):\s*(.*)$/);
81
+ if (!m) fail("bad list item", line);
82
+ return { [m[1]]: m[2] === "" ? null : parseScalar(m[2], line) };
83
+ }
84
+ function parseInlineMap(item, line) {
85
+ const out = {};
86
+ for (const part of splitTopLevel(item.slice(1, -1))) {
87
+ if (!part.trim()) continue;
88
+ const m = part.match(/^\s*([A-Za-z0-9_.-]+)\s*:\s*(.*)$/);
89
+ if (!m) fail(`bad inline map entry ${JSON.stringify(part)}`, line);
90
+ out[m[1]] = parseScalar(m[2].trim(), line);
91
+ }
92
+ return out;
93
+ }
94
+ const root = parseBlock(lines.length ? lines[0].indent : 0);
95
+ if (pos < lines.length) fail("could not parse to end of file", lines[pos]);
96
+ return root ?? {};
97
+ }
98
+ function stripComment(raw) {
99
+ let out = "";
100
+ let quote = null;
101
+ for (let i = 0; i < raw.length; i++) {
102
+ const c = raw[i];
103
+ if (quote) {
104
+ out += c;
105
+ if (c === quote && raw[i - 1] !== "\\") quote = null;
106
+ continue;
107
+ }
108
+ if (c === '"' || c === "'") {
109
+ quote = c;
110
+ out += c;
111
+ continue;
112
+ }
113
+ if (c === "#" && (i === 0 || /\s/.test(raw[i - 1]))) break;
114
+ out += c;
115
+ }
116
+ return out;
117
+ }
118
+ function splitTopLevel(s) {
119
+ const parts = [];
120
+ let depth = 0;
121
+ let cur = "";
122
+ for (const c of s) {
123
+ if (c === "{" || c === "[") depth++;
124
+ if (c === "}" || c === "]") depth--;
125
+ if (c === "," && depth === 0) {
126
+ parts.push(cur);
127
+ cur = "";
128
+ continue;
129
+ }
130
+ cur += c;
131
+ }
132
+ parts.push(cur);
133
+ return parts;
134
+ }
135
+ function parseScalar(raw, line) {
136
+ const v = raw.trim();
137
+ if (v.startsWith("[") && v.endsWith("]")) {
138
+ const inner = v.slice(1, -1).trim();
139
+ return inner === "" ? [] : splitTopLevel(inner).map((s) => parseScalar(s, line));
140
+ }
141
+ if (v.startsWith('"') && v.endsWith('"') || v.startsWith("'") && v.endsWith("'")) {
142
+ return v.slice(1, -1);
143
+ }
144
+ if (v === "true") return true;
145
+ if (v === "false") return false;
146
+ if (v === "null" || v === "~") return null;
147
+ if (/^-?\d+$/.test(v)) return Number(v);
148
+ return v;
149
+ }
150
+ var MAX_INCLUDE_DEPTH = 8;
151
+ var FENCE = "\0";
152
+ function render(template, ctx, readPartial, depth = 0) {
153
+ if (depth > MAX_INCLUDE_DEPTH) throw new Error("include depth exceeded; a partial probably includes itself");
154
+ let out = template.replace(
155
+ /\{\{#if\s+([A-Za-z0-9_.]+)\s*\}\}\n?([\s\S]*?)\{\{\/if\}\}\n?/g,
156
+ (_, path, body) => truthy(lookup(ctx, path)) ? body : ""
157
+ );
158
+ out = out.replace(/\{\{>(\??)\s*([^}\s]+)\s*\}\}/g, (_, optional, rel) => {
159
+ const partial = readPartial(rel);
160
+ if (partial === null) {
161
+ if (optional) return "";
162
+ throw new Error(`partial not found: ${rel}`);
163
+ }
164
+ return render(partial, ctx, readPartial, depth + 1).replace(/\n+$/, "");
165
+ });
166
+ out = out.replace(/\{\{\s*([A-Za-z0-9_.]+)\s*\}\}/g, (_, path) => {
167
+ const v = lookup(ctx, path);
168
+ if (v === void 0 || v === null) {
169
+ if (path.startsWith("event.")) {
170
+ throw new Error(
171
+ `{{${path}}} needs trigger context, which arrives as ROSTER_CONTEXT.
172
+ A "mention" prompt is written for the comment that woke it, so it cannot
173
+ be composed without one. To see it locally:
174
+ ROSTER_CONTEXT='{"issue_number":"1","comment_id":"1","repo":"o/r"}' \\
175
+ node compose.mjs --staff <handle> --kind <kind>`
176
+ );
177
+ }
178
+ throw new Error(`unknown or empty placeholder: {{${path}}}`);
179
+ }
180
+ return String(v).replace(/\{\{/g, FENCE);
181
+ });
182
+ return depth === 0 ? out.replaceAll(FENCE, "{{") : out;
183
+ }
184
+ function lookup(ctx, path) {
185
+ return path.split(".").reduce((acc, k) => acc == null ? void 0 : acc[k], ctx);
186
+ }
187
+ function truthy(v) {
188
+ return !(v === void 0 || v === null || v === false || v === "" || Array.isArray(v) && v.length === 0);
189
+ }
190
+ function readHumans(org) {
191
+ const listed = Array.isArray(org?.humans) ? org.humans : org?.humans ? [org.humans] : [];
192
+ const out = [];
193
+ for (const entry of [...listed, org?.human].filter(Boolean)) {
194
+ const github = String(entry.github ?? entry.login ?? "").trim();
195
+ const name = String(entry.name ?? github).trim();
196
+ if (!github && !name) continue;
197
+ if (github && out.some((h) => h.github.toLowerCase() === github.toLowerCase())) continue;
198
+ out.push({
199
+ github,
200
+ name: name || github,
201
+ marker: String(entry.marker ?? "").trim() || defaultMarker(name || github),
202
+ role: entry.role ?? void 0,
203
+ ...handlesOf(entry.handles).length ? { handles: handlesOf(entry.handles) } : {},
204
+ ...entry.view_only === true ? { viewOnly: true } : {}
205
+ });
206
+ }
207
+ return out;
208
+ }
209
+ function handlesOf(v) {
210
+ const list = Array.isArray(v) ? v : v ? String(v).split(",") : [];
211
+ return list.map((x) => String(x ?? "").trim()).filter(Boolean);
212
+ }
213
+ function handlesList(humans) {
214
+ if (humans.length < 2 || !humans.some((h) => h.handles?.length)) return "";
215
+ return humans.map((h) => {
216
+ const who = `- **${h.name}**${h.github ? ` (@${h.github}, label \`${h.marker}\`)` : ""}`;
217
+ return h.handles?.length ? `${who}: ${h.handles.join(", ")}` : `${who}: anything else`;
218
+ }).join("\n");
219
+ }
220
+ function humanSentence(humans) {
221
+ const parts = humans.map((h) => h.github ? `${h.name} (@${h.github})` : h.name);
222
+ if (parts.length < 2) return parts[0] ?? "";
223
+ return `${parts.slice(0, -1).join(", ")} and ${parts[parts.length - 1]}`;
224
+ }
225
+ function defaultMarker(name) {
226
+ return String(name).trim().split(/[\s-]+/)[0].toLowerCase().replace(/[^a-z0-9]/g, "") || "human";
227
+ }
228
+ function compose({
229
+ opsDir,
230
+ brainsDir,
231
+ staff,
232
+ kind,
233
+ runDir,
234
+ fs = nodeFs,
235
+ context = process.env.ROSTER_CONTEXT
236
+ }) {
237
+ const { readFileSync, existsSync } = fs;
238
+ const org = parseYaml(readFileSync(join(opsDir, "org.yaml"), "utf8"), "org.yaml");
239
+ const entry = (org.staff ?? []).find((s) => s.handle === staff);
240
+ if (!entry) {
241
+ const known = (org.staff ?? []).map((s) => s.handle).join(", ") || "none";
242
+ throw new Error(`unknown staff handle "${staff}". org.yaml knows: ${known}`);
243
+ }
244
+ const brainDir = resolve(brainsDir, entry.dir ?? entry.handle);
245
+ const staffFile = join(brainDir, "staff.yaml");
246
+ if (!existsSync(staffFile)) throw new Error(`no staff.yaml at ${staffFile}`);
247
+ const self2 = parseYaml(readFileSync(staffFile, "utf8"), `${entry.handle}/staff.yaml`);
248
+ const peers = (org.staff ?? []).filter((s) => s.handle !== staff).map((s) => ({ ...s, ...s.dir ? {} : { dir: s.handle } }));
249
+ let event = {};
250
+ if (context) {
251
+ try {
252
+ event = JSON.parse(context);
253
+ } catch (err) {
254
+ throw new Error(`ROSTER_CONTEXT is not valid JSON: ${err.message}`);
255
+ }
256
+ }
257
+ if (Object.keys(event).length) event = { ...event, no_comment: !event.comment_id };
258
+ const trigger = String(event.trigger ?? "");
259
+ event = {
260
+ ...event,
261
+ from_peer: trigger === "peer",
262
+ from_human: trigger !== "peer",
263
+ follow_on: trigger === "follow-on"
264
+ };
265
+ const routineId = String(event.routine ?? "");
266
+ let routine = null;
267
+ if (/^[a-z0-9][a-z0-9-]{0,39}$/.test(routineId)) {
268
+ const file = join(brainDir, "routines", `${routineId}.md`);
269
+ if (existsSync(file)) {
270
+ const text = readFileSync(file, "utf8").trimStart();
271
+ const heading = /^#\s+(.+)\n?/.exec(text);
272
+ routine = {
273
+ id: routineId,
274
+ title: heading ? heading[1].trim() : routineId,
275
+ body: (heading ? text.slice(heading[0].length) : text).trim()
276
+ };
277
+ } else {
278
+ routine = { id: routineId, title: routineId, body: "", missing: true };
279
+ }
280
+ }
281
+ const inflightFile = join(runDir ?? join(brainsDir, ".roster-run"), "inflight.md");
282
+ const inflight = existsSync(inflightFile) ? readFileSync(inflightFile, "utf8").trim() : "";
283
+ const everyone = readHumans(org);
284
+ const humans = everyone.filter((h) => !h.viewOnly);
285
+ const ctx = {
286
+ org,
287
+ event,
288
+ // The first is who the prose addresses; `humans` is everybody the mention gate accepts.
289
+ human: humans[0] ?? org.human,
290
+ humans,
291
+ ops: { dir: org.ops_dir ?? "roster-ops" },
292
+ // `dir` lives in the org registry (it is where the checkout lands), everything
293
+ // else lives in the staff member's own manifest.
294
+ staff: {
295
+ ...self2,
296
+ dir: entry.dir ?? entry.handle,
297
+ // The repo this role contributes to but does not own. Named explicitly in the
298
+ // prompt because "a repo you do not own" is vaguer than an agent needs.
299
+ product: (self2.works_in ?? [])[0] ?? null,
300
+ // Absent from manifests written before it existed; the callers fall back to the same.
301
+ max_runs_per_day: self2.max_runs_per_day ?? 6,
302
+ // One staff member drafts next month's org/priorities.md, so there is one draft rather
303
+ // than one per person: whoever org.yaml lists first.
304
+ drafts_priorities: (org.staff ?? [])[0]?.handle === staff
305
+ },
306
+ peers,
307
+ peer: peers[0] ?? null,
308
+ kind,
309
+ routine,
310
+ // Convenience strings the fragments lean on, computed once here so a
311
+ // fragment never has to do string work.
312
+ peer_list: peers.map((p) => `- \`${p.dir}/\` - the ${p.name}'s brain`).join("\n"),
313
+ // Everybody who can wake this staff member and rule on their work, and the same list
314
+ // without the one the prose already names. Empty when there is only one, which is what
315
+ // makes `{{#if humans_extra}}` the right way to mention the others at all.
316
+ human_list: humanSentence(humans),
317
+ inflight,
318
+ humans_extra: humanSentence(humans.slice(1)),
319
+ // Who looks after what, when an org has said. Empty for one person, and the rule goes.
320
+ humans_handles: handlesList(humans),
321
+ // Who can read along and cannot rule. Empty, and the paragraph gone, when nobody is.
322
+ humans_viewing: humanSentence(everyone.filter((h) => h.viewOnly)),
323
+ // The services this staff member may use, as a list for the prompt. Empty, and the section
324
+ // gone, when they have none. Whether each one's key is present is only known in the run.
325
+ connectors: connectorsOf(org, staff).filter((c) => !c.problem).map((c) => {
326
+ const ro = c.readOnly || self2.permissions === "read-only";
327
+ return `- **${c.name}**, as the \`${c.id}\` MCP server${ro ? ", read only" : ""}`;
328
+ }).join("\n")
329
+ };
330
+ const readPartial = (rel) => {
331
+ const p = rel.startsWith("staff:") ? join(brainDir, rel.slice(6)) : join(opsDir, rel);
332
+ return existsSync(p) ? readFileSync(p, "utf8") : null;
333
+ };
334
+ const kindFile = join(opsDir, "prompts", `${kind}.md`);
335
+ if (!existsSync(kindFile)) throw new Error(`no prompt for kind "${kind}" at ${kindFile}`);
336
+ const body = render(readFileSync(kindFile, "utf8"), ctx, readPartial);
337
+ return body.replace(/\n{3,}/g, "\n\n").trimEnd() + "\n";
338
+ }
339
+ function main(argv) {
340
+ const args = {};
341
+ for (let i = 0; i < argv.length; i += 2) {
342
+ if (!argv[i].startsWith("--")) throw new Error(`unexpected argument ${argv[i]}`);
343
+ args[argv[i].slice(2)] = argv[i + 1];
344
+ }
345
+ if (!args.staff || !args.kind) {
346
+ console.error("usage: node compose.mjs --staff <handle> --kind <daily|mention> [--ops DIR] [--brains DIR]");
347
+ process.exit(2);
348
+ }
349
+ const opsDir = resolve(args.ops ?? dirname(fileURLToPath(import.meta.url)));
350
+ const brainsDir = resolve(args.brains ?? join(opsDir, ".."));
351
+ process.stdout.write(compose({ opsDir, brainsDir, staff: args.staff, kind: args.kind }));
352
+ }
353
+ var self = import.meta.url ? fileURLToPath(import.meta.url) : "";
354
+ if (process.argv[1] && self.endsWith("compose.mjs") && resolve(process.argv[1]) === resolve(self)) {
355
+ try {
356
+ main(process.argv.slice(2));
357
+ } catch (err) {
358
+ console.error(`compose: ${err.message}`);
359
+ process.exit(1);
360
+ }
361
+ }
362
+
363
+ export {
364
+ parseYaml,
365
+ render,
366
+ readHumans,
367
+ handlesList,
368
+ humanSentence,
369
+ compose
370
+ };